﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;


namespace DAL
{
    public class DALRubros: DALBase
    {
        private static string cmdRubroPorId = "Select * From Rubros Where RubId = @RubId ";
        private static string cmdAltaRubro = "INSERT INTO Rubros (RubNombre, RubImagen) VALUES (@RubNombre, @RubImagen)";
        private static string cmdActualizar = "Update dbo.Rubros set  RubNombre = @RubNombre, RubImagen = @RubImagen Where RubId = @RubId";
        private static string cmdTodosLosRubros = "Select * From Rubros Order By 2 ASC";
        private static string cmdRubrosXComercio = "select r.RubId, r.RubNombre, r.RubImagen from Rubros r join ComercioRubros c on r.RubId = c.RubId where c.ComId = @ComId";

        public SqlDataReader BuscarRubroPorId(int RubroId)
        {            
            List<SqlParameter> lstparameters = new List<SqlParameter>();
            lstparameters.Add(new SqlParameter("@RubId", RubroId));
            SqlDataReader dr = select(lstparameters, cmdRubroPorId, CommandType.Text);

            return dr;
        }

        public static int AltaRubro(Hashtable ht)
        {

            List<SqlParameter> parametros = new List<SqlParameter>();
          //  parametros.Add(new SqlParameter("@RubId", ht["RubId"]));
            parametros.Add(new SqlParameter("@RubNombre", ht["RubNombre"]));
            parametros.Add(new SqlParameter("@RubImagen", ht["RubImagen"]));

            return ejecutaNonQuery(cmdAltaRubro, parametros, CommandType.Text);
        
        }

        public static int ModificarRubro(Hashtable ht)
        {

            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@RubId", ht["RubId"]));
            parametros.Add(new SqlParameter("@RubNombre", ht["RubNombre"]));
            parametros.Add(new SqlParameter("@RubImagen", ht["RubImagen"]));
            return ejecutaNonQuery(cmdActualizar, parametros, CommandType.Text);
        }

        public static SqlDataReader BuscarRubros()
        {
            SqlDataReader dr = select(null, cmdTodosLosRubros, CommandType.Text);
            return dr;
        }

        public static SqlDataReader BuscarRubrosXComercio(int comercioid) {
            List<SqlParameter> lstparameters = new List<SqlParameter>();
            lstparameters.Add(new SqlParameter("@ComId", comercioid));
            SqlDataReader dr = select(lstparameters, cmdRubrosXComercio, CommandType.Text);
            return dr;            
        }
    }
}
